﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ComponentModel.Composition;

namespace Kooboo.Commerce.Repositories
{
    [Export(typeof(IProductCustomField))]
    public partial class ProductCustomField : Entity, IProductCustomField
    {
        #region IProductCustomField Members
        ICustomField _CustomField2;
        ICustomField IProductCustomField.CustomField
        {
            get
            {
                if (this._CustomField2 == null)
                {
                    this._CustomField2 = this.DataContext.ProductAttributes
                        .Where(i => i.Id == this.CustomFieldId)
                        .FirstOrDefault();
                }

                return this._CustomField2;
            }
            set
            {
                this._CustomField2 = value;
                this.CustomFieldId = value.Id;
            }
        }

        IProduct _Product2;
        IProduct IProductCustomField.Product
        {
            get
            {
                if (this._Product2 == null)
                {
                    this._Product2 = this.DataContext.Products
                        .Where(i => i.Id == this.ProductId)
                        .FirstOrDefault();
                }

                return this._Product2;
            }
            set
            {
                this._Product2 = value;
                this.ProductId = value.Id;
            }
        }

        #endregion
    }
}
